﻿Imports VendasBLL
Imports VendasDAL
Public Class MarcaFRM
    Dim ObjBLL As New MarcaBLL
    Public Op As String
    Public codigo As Integer
#Region "Carrega Campos"
    Sub CarregaCampos(codigo As Integer)
        ObjBLL = New MarcaBLL(codigo)
        LBCodigo.Text = "Código: " & ObjBLL.Codigo
        LBTitulo.Text = ObjBLL.Descricao
        TXTDescricao.Text = ObjBLL.Descricao
        CBStatus.SelectedValue = ObjBLL.Status
    End Sub
#End Region

#Region "Limpar campos"
    Sub Limpa()
        CBStatus.SelectedValue = 1
        TXTDescricao.Text = ""
        Me.ObjBLL = Nothing
    End Sub
#End Region

#Region "Preenche campos"
    Sub PreencheCampos()
        CBStatus.SelectedValue = ObjBLL.Status
        TXTDescricao.Text = ObjBLL.Descricao
    End Sub

#End Region

#Region "Load"
    Private Sub CargoFRM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        objconexao.carregaCombo(CBStatus, "Generico.Gen_Status", "sta_codigo", "sta_descricao", "sta_codigo < 3", "sta_codigo")
        Limpa()
        If (Op = "I") Then
            LBCodigo.Visible = False
            LBTitulo.Text = "Marca"
            LBCodigo.Text = 0
        Else
            LBCodigo.Visible = True
            CarregaCampos(codigo)
        End If
    End Sub
#End Region

#Region "Salvar/Alterar"
    Private Sub TSBSalvar_Click(sender As System.Object, e As System.EventArgs) Handles TSBSalvar.Click

        Try

            ObjBLL = New MarcaBLL(codigo, StrConv(Trim(TXTDescricao.Text), VbStrConv.ProperCase), CBStatus.SelectedValue)
            If Op = "I" Then
                ObjBLL.Inserir()
                MessageBox.Show("Marca inserido com sucesso", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Limpa()
                Me.Close()
            Else
                ObjBLL.Alterar()
                MessageBox.Show("Marca alterada com sucesso", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Limpa()
                Me.Close()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message, "Atenção", MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Sub
#End Region

#Region "Voltar"
    Private Sub TSBVoltar_Click(sender As System.Object, e As System.EventArgs) Handles TSBVoltar.Click
        Me.Close()
    End Sub
#End Region

    Private Sub MarcaFRM_KeyDown(sender As System.Object, e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
        If (e.KeyCode = Keys.Escape) Then
            Me.Close()
        End If
    End Sub
End Class